﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using UygulamaTakbisService.wsTakbisServis;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Diagnostics;

namespace UygulamaTakbisService
{
    public class SbiDao : IDisposable
    {
        TAKBISWebService takbisServis = new TAKBISWebService();

        public bool SbiKaydet(SBI sbi, decimal? ustSbiID, TapuBolum tapuBolum, decimal? referans)
        {
            bool sonuc;
            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TakbisBilgiSorguLogConnection"].ToString()))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    con.Open();
                    SqlTransaction transaction = con.BeginTransaction("trans");
                    try
                    {
                        cmd.CommandText = @"insert into Sbi with(updlock) (SbiID,SBISablon,TapuBolumDurum,SBICumle,BaslamaTarih,BitisTarih,Sure,BirimBilgiID,TesisIslemBilgiID,TerkinIslemBilgiID,TbsbAktifMi,TbsbTesisIslemBilgiID,TbsbTerkinIslemBilgiID,UstSbiID,KayitTarih,TapuBolum,Referans) values (@SbiID,@SBISablon,@TapuBolumDurum,@SBICumle,@BaslamaTarih,@BitisTarih,@Sure,@BirimBilgiID,@TesisIslemBilgiID,@TerkinIslemBilgiID,@TbsbAktifMi,@TbsbTesisIslemBilgiID,@TbsbTerkinIslemBilgiID,@UstSbiID,GETDATE(),@TapuBolum,@Referans)";

                        if (sbi.SbiID != null)
                            cmd.Parameters.Add("@SbiID", sbi.SbiID);
                        else
                            cmd.Parameters.Add("@SbiID", DBNull.Value);

                        if (sbi.SBISablon != null)
                            cmd.Parameters.Add("@SBISablon", sbi.SBISablon.ID);
                        else
                            cmd.Parameters.Add("@SBISablon", DBNull.Value);

                        if (sbi.TapuBolumDurum != null)
                            cmd.Parameters.Add("@TapuBolumDurum", (byte)sbi.TapuBolumDurum);
                        else
                            cmd.Parameters.Add("@TapuBolumDurum", DBNull.Value);

                        if (sbi.SBICumle != null)
                            cmd.Parameters.Add("@SBICumle", sbi.SBICumle);
                        else
                            cmd.Parameters.Add("@SBICumle", DBNull.Value);

                        if (sbi.BaslamaTarih != null)
                            cmd.Parameters.Add("@BaslamaTarih", sbi.BaslamaTarih);
                        else
                            cmd.Parameters.Add("@BaslamaTarih", DBNull.Value);

                        if (sbi.BitisTarih != null)
                            cmd.Parameters.Add("@BitisTarih", sbi.BitisTarih);
                        else
                            cmd.Parameters.Add("@BitisTarih", DBNull.Value);

                        if (sbi.Sure != null)
                            cmd.Parameters.Add("@Sure", sbi.Sure);
                        else
                            cmd.Parameters.Add("@Sure", DBNull.Value);

                        if (sbi.SureBirim != null)
                            cmd.Parameters.Add("@BirimBilgiID", sbi.SureBirim.BirimBilgiID);
                        else
                            cmd.Parameters.Add("@BirimBilgiID", DBNull.Value);

                        if (sbi.TesisIslem != null)
                            cmd.Parameters.Add("@TesisIslemBilgiID", sbi.TesisIslem.IslemBilgiID);
                        else
                            cmd.Parameters.Add("@TesisIslemBilgiID", DBNull.Value);

                        if (sbi.TerkinIslem != null)
                            cmd.Parameters.Add("@TerkinIslemBilgiID", sbi.TerkinIslem.IslemBilgiID);
                        else
                            cmd.Parameters.Add("@TerkinIslemBilgiID", DBNull.Value);

                        if (sbi.TbsbAktifMi != null)
                            cmd.Parameters.Add("@TbsbAktifMi", (byte)sbi.TbsbAktifMi);
                        else
                            cmd.Parameters.Add("@TbsbAktifMi", DBNull.Value);

                        if (sbi.TbsbTesisIslem != null)
                            cmd.Parameters.Add("@TbsbTesisIslemBilgiID", sbi.TbsbTesisIslem.IslemBilgiID);
                        else
                            cmd.Parameters.Add("@TbsbTesisIslemBilgiID", DBNull.Value);

                        if (sbi.TerkinIslem != null)
                            cmd.Parameters.Add("@TbsbTerkinIslemBilgiID", sbi.TerkinIslem.IslemBilgiID);
                        else
                            cmd.Parameters.Add("@TbsbTerkinIslemBilgiID", DBNull.Value);

                        if (ustSbiID != null)
                            cmd.Parameters.Add("@UstSbiID", ustSbiID);
                        else
                            cmd.Parameters.Add("@UstSbiID", DBNull.Value);

                        cmd.Parameters.Add("@TapuBolum", (byte)tapuBolum);

                        if (referans != null)
                            cmd.Parameters.Add("@Referans", referans);
                        else
                            cmd.Parameters.Add("@Referans", DBNull.Value);

                        cmd.Connection = con;
                        cmd.Transaction = transaction;
                        cmd.ExecuteScalar();
                        transaction.Commit();
                        sonuc = true;
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        sonuc = false;
                        using (ExceptionLogDao el = new ExceptionLogDao())
                        {
                            el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                        }
                    }
                    finally
                    {
                        con.Close();
                        con.Dispose();
                        cmd.Dispose();
                    }

                    if (sonuc)
                    {
                        //SBI TesisIslemBilgi Kayıt
                        if (sbi.TesisIslem != null)
                        {
                            using (IslemBilgiDao islemBilgiDao = new IslemBilgiDao())
                            {
                                if (!islemBilgiDao.IslemBilgiKayitliMi(sbi.TesisIslem))
                                {
                                    bool tesisIslemBilgiKayitEdildiMi = islemBilgiDao.IslemBilgiKaydet(sbi.TesisIslem);

                                    if (tesisIslemBilgiKayitEdildiMi = true && !islemBilgiDao.YevmiyeBilgiKayitliMi(sbi.TesisIslem.Yevmiye))
                                    {
                                        bool tesisYevmiyeBilgiKayitEdildiMi = islemBilgiDao.YevmiyeBilgiKaydet(sbi.TesisIslem.Yevmiye);
                                    }
                                }
                            }
                        }

                        //SBI TerkinIslemBilgi Kayıt
                        if (sbi.TerkinIslem != null)
                        {
                            using (IslemBilgiDao islemBilgiDao = new IslemBilgiDao())
                            {
                                if (!islemBilgiDao.IslemBilgiKayitliMi(sbi.TerkinIslem))
                                {
                                    bool terkinIslemBilgiKayitEdildiMi = islemBilgiDao.IslemBilgiKaydet(sbi.TerkinIslem);

                                    if (terkinIslemBilgiKayitEdildiMi = true && !islemBilgiDao.YevmiyeBilgiKayitliMi(sbi.TerkinIslem.Yevmiye))
                                    {
                                        bool terkinYevmiyeBilgiKayitEdildiMi = islemBilgiDao.YevmiyeBilgiKaydet(sbi.TerkinIslem.Yevmiye);
                                    }
                                }
                            }
                        }

                        //TBSBSBI TesisIslemBilgi Kayıt
                        if (sbi.TbsbTesisIslem != null)
                        {
                            using (IslemBilgiDao islemBilgiDao = new IslemBilgiDao())
                            {
                                if (!islemBilgiDao.IslemBilgiKayitliMi(sbi.TbsbTesisIslem))
                                {
                                    bool tesisIslemBilgiKayitEdildiMi = islemBilgiDao.IslemBilgiKaydet(sbi.TbsbTesisIslem);

                                    if (tesisIslemBilgiKayitEdildiMi = true && !islemBilgiDao.YevmiyeBilgiKayitliMi(sbi.TbsbTesisIslem.Yevmiye))
                                    {
                                        bool tesisYevmiyeBilgiKayitEdildiMi = islemBilgiDao.YevmiyeBilgiKaydet(sbi.TbsbTesisIslem.Yevmiye);
                                    }
                                }
                            }
                        }

                        //TBSBSBI TerkinIslemBilgi Kayıt
                        if (sbi.TbsbTerkinIslem != null)
                        {
                            using (IslemBilgiDao islemBilgiDao = new IslemBilgiDao())
                            {
                                if (!islemBilgiDao.IslemBilgiKayitliMi(sbi.TbsbTerkinIslem))
                                {
                                    bool terkinIslemBilgiKayitEdildiMi = islemBilgiDao.IslemBilgiKaydet(sbi.TbsbTerkinIslem);

                                    if (terkinIslemBilgiKayitEdildiMi = true && !islemBilgiDao.YevmiyeBilgiKayitliMi(sbi.TbsbTerkinIslem.Yevmiye))
                                    {
                                        bool terkinYevmiyeBilgiKayitEdildiMi = islemBilgiDao.YevmiyeBilgiKaydet(sbi.TbsbTerkinIslem.Yevmiye);
                                    }
                                }
                            }
                        }
                    }

                    return sonuc;
                }
            }
        }

        public bool SbiSablonKaydet(SBISablon sbiSablon)
        {
            bool sonuc;
            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TakbisBilgiSorguLogConnection"].ToString()))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    con.Open();
                    SqlTransaction transaction = con.BeginTransaction("trans");
                    try
                    {
                        cmd.CommandText = @"insert into SBISablon with(updlock) (SbiSablonBilgiID,Ad,KayitTarih) values (@SbiSablonBilgiID,@Ad,GETDATE())  ";

                        if (sbiSablon.ID != null)
                            cmd.Parameters.Add("@SbiSablonBilgiID", sbiSablon.ID);
                        else
                            cmd.Parameters.Add("@SbiSablonBilgiID", DBNull.Value);

                        if (sbiSablon.Ad != null)
                            cmd.Parameters.Add("@Ad", sbiSablon.Ad);
                        else
                            cmd.Parameters.Add("@Ad", DBNull.Value);

                        cmd.Connection = con;
                        cmd.Transaction = transaction;
                        cmd.ExecuteScalar();
                        transaction.Commit();
                        sonuc = true;
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        sonuc = false;
                        using (ExceptionLogDao el = new ExceptionLogDao())
                        {
                            el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                        }
                    }
                    finally
                    {
                        con.Close();
                        con.Dispose();
                        cmd.Dispose();
                    }
                    return sonuc;
                }
            }
        }

        public bool SbiSablonKayitliMi(decimal sbiSablonBilgiID)
        {
            bool sonuc = false;
            try
            {
                using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TakbisBilgiSorguLogConnection"].ToString()))
                {
                    string sql = string.Format(@"SELECT * FROM SBISablon with(nolock) WHERE SbiSablonBilgiID = {0} ", sbiSablonBilgiID);
                    using (SqlCommand cmd = new SqlCommand(sql))
                    {
                        using (SqlDataAdapter sda = new SqlDataAdapter())
                        {
                            cmd.Connection = con;
                            sda.SelectCommand = cmd;
                            cmd.CommandTimeout = 60000;
                            DataTable dt = new DataTable();
                            sda.Fill(dt);
                            if (dt.Rows.Count >= 1)
                                sonuc = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return sonuc;
        }

        public bool SerhBeyanIrtifakKaydet(List<SBI> sbiList, TapuBolum tapuBolum, decimal referans)
        {
            bool sonuc = false;
            try
            {
                foreach (SBI sbi in sbiList)
                {
                    //SBISablon Kayıtlı Değilİse Kayıt Ediyor
                    if (!SbiSablonKayitliMi(sbi.SBISablon.ID))
                        SbiSablonKaydet(sbi.SBISablon);

                    //Sbi Yi Kayıt Ediyor
                    bool sbiKayitEdildiMi = SbiKaydet(sbi, null, tapuBolum, referans);

                    //Sbi Ye Bağlı Ust Sbi Yi Kayıt Ediyor
                    if (sbiKayitEdildiMi)
                    {
                        foreach (SBI ustSbi in sbi.Sbi)
                        {
                            bool ustSbiKayitEdildiMi = SbiKaydet(ustSbi, sbi.SbiID, TapuBolum.Serh, sbi.SbiID);
                        }

                        using (HissedarDao hissedarDao = new HissedarDao())
                        {
                            foreach (Hissedar hissedar in sbi.HissedarList)
                            {
                                bool hissedarKayitEdildiMi = hissedarDao.HissedarKaydet(hissedar, TapuBolum.SerhBeyanMalik, sbi.SbiID);
                            }
                        }
                    }
                }
                sonuc = true;
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return sonuc;
        }

        public List<SBI> GetirSerhTasinmazIDDen(decimal tasinmazID, TapuBolumDurum tapuBolumDurum, long kullaniciID)
        {
            List<SBI> sbiList = null;
            try
            {
                using (LogDao logDao = new LogDao())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    sbiList = takbisServis.GetirSerhTasinmazIDDen(tasinmazID, tapuBolumDurum).ToList();
                    stopwatch.Stop();

                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    if (sbiList.Count > 0)
                    {
                        bool sbiKayitEdildiMi = SerhBeyanIrtifakKaydet(sbiList, TapuBolum.Tasinmaz, tasinmazID);
                    }
                    stopwatch2.Stop();
                    logDao.TakbisBilgiSorguLogKaydet("GetirSerhTasinmazIDDen", null, sbiList, "TaşınmazID = " + tasinmazID + ", TapuBolumDurum = " + tapuBolumDurum.ToString(), Convert.ToDecimal(stopwatch.ElapsedMilliseconds), Convert.ToDecimal(stopwatch2.ElapsedMilliseconds), kullaniciID);
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return sbiList;
        }

        public List<SBI> GetirBeyanTasinmazIDDen(decimal tasinmazID, TapuBolumDurum tapuBolumDurum, long kullaniciID)
        {
            List<SBI> sbiList = null;
            try
            {
                using (LogDao logDao = new LogDao())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    sbiList = takbisServis.GetirBeyanTasinmazIDDen(tasinmazID, tapuBolumDurum).ToList();
                    stopwatch.Stop();

                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    bool sbiKayitEdildiMi = SerhBeyanIrtifakKaydet(sbiList, TapuBolum.Tasinmaz, tasinmazID);
                    stopwatch2.Stop();
                    logDao.TakbisBilgiSorguLogKaydet("GetirBeyanTasinmazIDDen", null, sbiList, "TaşınmazID = " + tasinmazID + ", TapuBolumDurum = " + tapuBolumDurum.ToString(), Convert.ToDecimal(stopwatch.ElapsedMilliseconds), Convert.ToDecimal(stopwatch2.ElapsedMilliseconds), kullaniciID);
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return sbiList;
        }

        public List<SBI> GetirIrtifakTasinmazIDDen(decimal tasinmazID, TapuBolumDurum tapuBolumDurum, long kullaniciID)
        {
            List<SBI> sbiList = null;
            try
            {
                using (LogDao logDao = new LogDao())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    sbiList = takbisServis.GetirIrtifakTasinmazIDDen(tasinmazID, tapuBolumDurum).ToList();
                    stopwatch.Stop();

                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    bool sbiKayitEdildiMi = SerhBeyanIrtifakKaydet(sbiList, TapuBolum.Tasinmaz, tasinmazID);
                    stopwatch2.Stop();
                    logDao.TakbisBilgiSorguLogKaydet("GetirIrtifakTasinmazIDDen", null, sbiList, "TaşınmazID = " + tasinmazID + ", TapuBolumDurum = " + tapuBolumDurum.ToString(), Convert.ToDecimal(stopwatch.ElapsedMilliseconds), Convert.ToDecimal(stopwatch2.ElapsedMilliseconds), kullaniciID);
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return sbiList;
        }

        public List<SBI> GetirSerhGercekKisiIDDen(decimal gercekKisiID, TapuBolumDurum tapuBolumDurum, long kullaniciID)
        {
            List<SBI> sbiList = null;
            try
            {
                using (LogDao logDao = new LogDao())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    sbiList = takbisServis.GetirSerhGercekKisiIDDen(gercekKisiID, tapuBolumDurum).ToList();
                    stopwatch.Stop();

                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    if (sbiList.Count > 0)
                    {
                        bool sbiKayitEdildiMi = SerhBeyanIrtifakKaydet(sbiList, TapuBolum.GercekKisi, gercekKisiID);
                    }
                    stopwatch2.Stop();
                    logDao.TakbisBilgiSorguLogKaydet("GetirSerhGercekKisiIDDen", null, sbiList, "GerçekKişiID = " + gercekKisiID + ", TapuBolumDurum = " + tapuBolumDurum.ToString(), Convert.ToDecimal(stopwatch.ElapsedMilliseconds), Convert.ToDecimal(stopwatch2.ElapsedMilliseconds), kullaniciID);
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return sbiList;
        }

        public List<SBI> GetirBeyanGercekKisiDen(decimal gercekKisiID, TapuBolumDurum tapuBolumDurum, long kullaniciID)
        {
            List<SBI> sbiList = null;
            try
            {
                using (LogDao logDao = new LogDao())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    sbiList = takbisServis.GetirBeyanGercekKisiDen(gercekKisiID, tapuBolumDurum).ToList();
                    stopwatch.Stop();

                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    bool sbiKayitEdildiMi = SerhBeyanIrtifakKaydet(sbiList, TapuBolum.GercekKisi, gercekKisiID);
                    stopwatch2.Stop();
                    logDao.TakbisBilgiSorguLogKaydet("GetirBeyanGercekKisiDen", null, sbiList, "GerçekKişiID = " + gercekKisiID + ", TapuBolumDurum = " + tapuBolumDurum.ToString(), Convert.ToDecimal(stopwatch.ElapsedMilliseconds), Convert.ToDecimal(stopwatch2.ElapsedMilliseconds), kullaniciID);
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return sbiList;
        }

        public List<SBI> GetirIrtifakGercekKisiDen(decimal gercekKisiID, TapuBolumDurum tapuBolumDurum, long kullaniciID)
        {
            List<SBI> sbiList = null;
            try
            {
                using (LogDao logDao = new LogDao())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    sbiList = takbisServis.GetirIrtifakGercekKisiDen(gercekKisiID, tapuBolumDurum).ToList();
                    stopwatch.Stop();

                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    bool sbiKayitEdildiMi = SerhBeyanIrtifakKaydet(sbiList, TapuBolum.GercekKisi, gercekKisiID);
                    stopwatch2.Stop();
                    logDao.TakbisBilgiSorguLogKaydet("GetirIrtifakGercekKisiDen", null, sbiList, "GerçekKişiID = " + gercekKisiID + ", TapuBolumDurum = " + tapuBolumDurum.ToString(), Convert.ToDecimal(stopwatch.ElapsedMilliseconds), Convert.ToDecimal(stopwatch2.ElapsedMilliseconds), kullaniciID);
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return sbiList;
        }

        public List<SBI> GetirSerhTuzelKisiIDDen(decimal tuzelKisiID, TapuBolumDurum tapuBolumDurum, long kullaniciID)
        {
            List<SBI> sbiList = null;
            try
            {
                using (LogDao logDao = new LogDao())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    sbiList = takbisServis.GetirSerhTuzelKisiIDDen(tuzelKisiID, tapuBolumDurum).ToList();
                    stopwatch.Stop();

                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    if (sbiList.Count > 0)
                    {
                        bool sbiKayitEdildiMi = SerhBeyanIrtifakKaydet(sbiList, TapuBolum.TuzelKisi, tuzelKisiID);
                    }
                    stopwatch2.Stop();
                    logDao.TakbisBilgiSorguLogKaydet("GetirSerhTuzelKisiIDDen", null, sbiList, "TüzelKişiID = " + tuzelKisiID + ", TapuBolumDurum = " + tapuBolumDurum.ToString(), Convert.ToDecimal(stopwatch.ElapsedMilliseconds), Convert.ToDecimal(stopwatch2.ElapsedMilliseconds), kullaniciID);
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return sbiList;
        }

        public List<SBI> GetirBeyanTuzelKisiDen(decimal tuzelKisiID, TapuBolumDurum tapuBolumDurum, long kullaniciID)
        {
            List<SBI> sbiList = null;
            try
            {
                using (LogDao logDao = new LogDao())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    sbiList = takbisServis.GetirBeyanTuzelKisiDen(tuzelKisiID, tapuBolumDurum).ToList();
                    stopwatch.Stop();

                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    bool sbiKayitEdildiMi = SerhBeyanIrtifakKaydet(sbiList, TapuBolum.TuzelKisi, tuzelKisiID);
                    stopwatch2.Stop();
                    logDao.TakbisBilgiSorguLogKaydet("GetirBeyanTuzelKisiDen", null, sbiList, "TüzelKişiID = " + tuzelKisiID + ", TapuBolumDurum = " + tapuBolumDurum.ToString(), Convert.ToDecimal(stopwatch.ElapsedMilliseconds), Convert.ToDecimal(stopwatch2.ElapsedMilliseconds), kullaniciID);
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return sbiList;
        }

        public List<SBI> GetirIrtifakTuzelKisiDen(decimal tuzelKisiID, TapuBolumDurum tapuBolumDurum, long kullaniciID)
        {
            List<SBI> sbiList = null;
            try
            {
                using (LogDao logDao = new LogDao())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    sbiList = takbisServis.GetirIrtifakTuzelKisiDen(tuzelKisiID, tapuBolumDurum).ToList();
                    stopwatch.Stop();

                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    bool sbiKayitEdildiMi = SerhBeyanIrtifakKaydet(sbiList, TapuBolum.TuzelKisi, tuzelKisiID);
                    stopwatch2.Stop();
                    logDao.TakbisBilgiSorguLogKaydet("GetirIrtifakTuzelKisiDen", null, sbiList, "TüzelKişiID = " + tuzelKisiID + ", TapuBolumDurum = " + tapuBolumDurum.ToString(), Convert.ToDecimal(stopwatch.ElapsedMilliseconds), Convert.ToDecimal(stopwatch2.ElapsedMilliseconds), kullaniciID);
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return sbiList;
        }

        public List<SBI> GetirSerhZeminHisseIDDen(decimal zeminHisseID, TapuBolumDurum tapuBolumDurum, long kullaniciID)
        {
            List<SBI> sbiList = null;
            try
            {
                using (LogDao logDao = new LogDao())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    sbiList = takbisServis.GetirSerhZeminHisseIDDen(zeminHisseID, tapuBolumDurum).ToList();
                    stopwatch.Stop();

                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    if (sbiList.Count > 0)
                    {
                        bool sbiKayitEdildiMi = SerhBeyanIrtifakKaydet(sbiList, TapuBolum.TasinmazHisse, zeminHisseID);
                    }
                    stopwatch2.Stop();
                    logDao.TakbisBilgiSorguLogKaydet("GetirSerhZeminHisseIDDen", null, sbiList, "ZeminHisseID = " + zeminHisseID + ", TapuBolumDurum = " + tapuBolumDurum.ToString(), Convert.ToDecimal(stopwatch.ElapsedMilliseconds), Convert.ToDecimal(stopwatch2.ElapsedMilliseconds), kullaniciID);
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return sbiList;
        }

        public List<SBI> GetirBeyanZeminHisseIDDen(decimal zeminHisseID, TapuBolumDurum tapuBolumDurum, long kullaniciID)
        {
            List<SBI> sbiList = null;
            try
            {
                using (LogDao logDao = new LogDao())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    sbiList = takbisServis.GetirBeyanZeminHisseIDDen(zeminHisseID, tapuBolumDurum).ToList();
                    stopwatch.Stop();

                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    if (sbiList.Count > 0)
                    {
                        bool sbiKayitEdildiMi = SerhBeyanIrtifakKaydet(sbiList, TapuBolum.TasinmazHisse, zeminHisseID);
                    }
                    stopwatch2.Stop();
                    logDao.TakbisBilgiSorguLogKaydet("GetirBeyanZeminHisseIDDen", null, sbiList, "ZeminHisseID = " + zeminHisseID + ", TapuBolumDurum = " + tapuBolumDurum.ToString(), Convert.ToDecimal(stopwatch.ElapsedMilliseconds), Convert.ToDecimal(stopwatch2.ElapsedMilliseconds), kullaniciID);
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return sbiList;
        }

        public List<SBI> GetirIrtifakZeminHisseIDDen(decimal zeminHisseID, TapuBolumDurum tapuBolumDurum, long kullaniciID)
        {
            List<SBI> sbiList = null;
            try
            {
                using (LogDao logDao = new LogDao())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    sbiList = takbisServis.GetirIrtifakZeminHisseIDDen(zeminHisseID, tapuBolumDurum).ToList();
                    stopwatch.Stop();

                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    if (sbiList.Count > 0)
                    {
                        bool sbiKayitEdildiMi = SerhBeyanIrtifakKaydet(sbiList, TapuBolum.TasinmazHisse, zeminHisseID);
                    }
                    stopwatch2.Stop();
                    logDao.TakbisBilgiSorguLogKaydet("GetirIrtifakZeminHisseIDDen", null, sbiList, "ZeminHisseID = " + zeminHisseID + ", TapuBolumDurum = " + tapuBolumDurum.ToString(), Convert.ToDecimal(stopwatch.ElapsedMilliseconds), Convert.ToDecimal(stopwatch2.ElapsedMilliseconds), kullaniciID);
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return sbiList;
        }

        public List<SBI> GetirSerhRehinDetayIDDen(decimal rehindetayID, TapuBolumDurum tapuBolumDurum, long kullaniciID)
        {
            List<SBI> sbiList = null;
            try
            {
                using (LogDao logDao = new LogDao())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    sbiList = takbisServis.GetirSerhRehinDetayIDDen(rehindetayID, tapuBolumDurum).ToList();
                    stopwatch.Stop();

                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    if (sbiList.Count > 0)
                    {
                        bool sbiKayitEdildiMi = SerhBeyanIrtifakKaydet(sbiList, TapuBolum.RehinDetay, rehindetayID);
                    }
                    stopwatch2.Stop();
                    logDao.TakbisBilgiSorguLogKaydet("GetirSerhRehinDetayIDDen", null, sbiList, "RehinDetayID = " + rehindetayID + ", TapuBolumDurum = " + tapuBolumDurum.ToString(), Convert.ToDecimal(stopwatch.ElapsedMilliseconds), Convert.ToDecimal(stopwatch2.ElapsedMilliseconds), kullaniciID);
                }
            }
            catch (Exception ex)
            {
                using (ExceptionLogDao el = new ExceptionLogDao())
                {
                    el.HataLogYaz(DateTime.Now.ToString() + "  " + ex.ToString());
                }
            }
            return sbiList;
        }

        public void Dispose()
        {
        }
    }
}
